package com.zjitc.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.zjitc.po.Country;
import com.zjitc.service.CountryService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/3/26 15:00
 * @description:
 */
@Controller
public class CountryConller {
  @Autowired
  private CountryService countryService;

  @RequestMapping("/findAll")
  public void findCounies(){
    List<Country> countries=countryService.findAllCountries();
    StringBuilder builder =new StringBuilder();
    for (Country country : countries){
     builder.append(country.toString());
     builder.append("\n");
     }
     System.out.println(builder);
  }



@RequestMapping("/findPage")
public  void findPageCountries(
@RequestParam(name = "start",required = false,defaultValue = "1") int start,
@RequestParam(name = "count",required = false,defaultValue = "5") int count
    ){
    List<Country> countries = countryService.findCountryies(start,count);
    StringBuilder builder =new StringBuilder();
    for (Country country : countries){
    builder.append(country.toString());
    builder.append("\n");
    }
    System.out.println(builder);

  System.out.println((Page)countries);

  PageInfo info= new PageInfo(countries);

  System.out.println(info);
    }
    }
